package com.bainc.web.client;

import com.bainc.web.shared.LoginInfo;
import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.core.client.GWT;
import com.google.gwt.user.client.rpc.AsyncCallback;

public class ProfileEntryPoint implements EntryPoint {
	
	class LoginServiceAsyncCallback implements AsyncCallback<LoginInfo> {
		@Override
		public void onFailure(Throwable caught) {
		}

		@Override
		public void onSuccess(LoginInfo info) {
			// Redirect user to appropriate page based on login status.
			if (info.isLoggedIn()) {
				UserProfilePage.load(info);
			} else {
				UserLoginPage.load(info);
			}
		}
	}

	@Override
	public void onModuleLoad() {
		LoginServiceAsync loginService = GWT.create(LoginService.class);
		LoginServiceAsyncCallback loginCallback = new LoginServiceAsyncCallback();
		loginService.login(GWT.getHostPageBaseURL(), loginCallback);
	}
}
